package com.extremelylargepackage.entity;

public class AiRandomAttack implements AiAttackComponent
{
	private Enemy _me;
	private float _fireChance;
	
	private long _timeSinceLastDecision;
	
	public AiRandomAttack(float fireChance)
	{
		_fireChance = fireChance;
		_timeSinceLastDecision = 0;
	}
	
	@Override
	public void setSelf(Enemy me) 
	{
		_me = me;
	}

	@Override
	public void peformAttack(long time) 
	{
		if(_me._weapon.canFire() && _timeSinceLastDecision > (1000/_me._weapon._fireRate))
		{
			if(Math.random() < _fireChance)
				_me._weapon.fire();
			_timeSinceLastDecision = 0;
		}
		else
			_timeSinceLastDecision += time;
	}
	
	public Object clone()
	{
		return new AiRandomAttack(_fireChance);
	}
}
